"""
Case Type   : 资源池化
Case Name   : XML配置扩容节点和指定节点不一致
Create At   : 2024.10
Owner       : chen
Description :
    1.准备Xml配置扩容节点信息
    2.执行扩容，指定xml、-h指定节点与扩容节点不一致
Expect      :
    1.成功
    2.合理报错
"""

import os
import unittest
from testcase.utils.Logger import Logger
from testcase.utils.CommonSH import CommonSH
from yat.test import Node
from yat.test import macro

class SharedStorage(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.log.info(f'-----{os.path.basename(__file__)} start-----')
        self.pri_node = Node('PrimaryDbUser')
        self.pri_root_node = Node('PrimaryRoot')
        self.sta2_node = Node('Standby2DbUser')
        self.commsh = CommonSH('PrimaryDbUser')
        self.db_host = self.sta2_node.db_host
        self.s_user = self.pri_node.ssh_user

    def test_shared_storage(self):
        text = "-----step1: 准备Xml配置扩容节点信息 expect: 成功-----"
        self.log.info(text)
        xml_path = macro.DB_XML_PATH
        xml_name = os.path.basename(xml_path)
        self.log.info('xml配置信息: ' + xml_name)

        text = f'-----step2: 执行扩容，指定xml、-h指定节点与扩容节点不一致' \
            f' expect: 合理报错-----'
        self.log.info(text)
        cmd = f''' gs_expansion -U {self.s_user} \
            -G {self.s_user} -X {xml_path} -h 10.10.10.10'''
        execute_cmd = f'''source {macro.DB_ENV_PATH};
            expect <<EOF
            set timeout 300
            spawn {cmd}
            expect "*assword*:"
            send "{self.pri_root_node.ssh_password}\\n"
            expect "*assword*:"
            send "{self.pri_root_node.ssh_password}\\n"
            expect "*lease repeat for database*:"
            send "{macro.GAUSSDB_INIT_USER_PASSWD}\\n"
            expect eof\n''' + '''EOF'''
        self.log.info(execute_cmd)
        res = self.pri_root_node.sh(execute_cmd).result()
        self.log.info(res)
        self.assertIn(f'''Unrecognized parameter''', 
            res)

    def tearDown(self):
        self.log.info(f'-----{os.path.basename(__file__)} end-----')